package com.mdlaser.controller;

import com.mdlaser.annotation.CommonRest;
import com.mdlaser.entity.WishLanguage;
import com.mdlaser.entity.WishType;
import com.mdlaser.service.IWishTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mdlaser
 * @since 2024-05-16
 */
@RestController
@RequestMapping("/wish-type")
@CommonRest
@Tag(name = "祝福类型管理")
public class WishTypeController {

    @Autowired
    IWishTypeService wishTypeService;

    @Operation(summary = "删除祝福类型")
    @GetMapping("/del")
    public void del(@RequestParam String wishId) {
        wishTypeService.getBaseMapper().deleteById(wishId);
    }


    @Operation(summary = "获取所有祝福类型")
    @GetMapping("/list")
    public Object list() {
        List<WishType> wishTypes = wishTypeService.getBaseMapper().selectList(null);
        HashMap<Object, Object> res = new HashMap<>();
        ArrayList<Object> resList = new ArrayList<>();
        wishTypes.forEach(w->{
            HashMap<String, Object> objMap = new HashMap<>();
            objMap.put("label",w.getWishType());
            objMap.put("value",w.getWishId());
            resList.add(objMap);
        });
        res.put("options",resList);
        return res;
    }

    @Operation(summary = "新增祝福类型")
    @PostMapping("/add")
    public void add(@RequestBody WishType wishType) {
        wishTypeService.getBaseMapper().insert(wishType);
    }




    @Operation(summary = "根据Id获取祝福语")
    @GetMapping("/getById")
    public WishType getById(@RequestParam String languageId) {
        return wishTypeService.getBaseMapper().selectById(languageId);
    }


    @Operation(summary = "根据Id修改祝福语")
    @PostMapping("/editById")
    public void editById(@RequestBody WishType wishType) {
        wishTypeService.getBaseMapper().updateById(wishType);
    }


}
